/**
 *  初始化 脱敏列表 默认 全部字段（列） 导入 不脱敏, 多张表 中字段（列）是都导入 是否脱敏 脱敏类型 脱敏方式
 * {
 *   tableName: { columnName: {dataLevelId: 脱敏类型, dataMaskingType: 'md5', importColumn: 是否导入, masking: 脱敏}  }
 * }
 * @param tables  所有需要脱敏的表
 * @param historyDesensitization  历史脱敏配置
 * @author Jinhui Hou
 */
export function initDesensitizationList(
  tables: any[],
  historyDesensitization: any
) {
  const tableDesensitizationMap: { [key: string]: any } = {}
  tables.forEach((table: any) => {
    const columnMap: any = {} // 每张表对应的脱敏配置
    table.head.forEach((column: any) => {
      const columnKey: string =
        typeof column === 'string' ? column : column.name
      let columnHistory: any = {}
      if (
        historyDesensitization &&
        historyDesensitization[table.tableName] &&
        historyDesensitization[table.tableName][columnKey]
      ) {
        columnHistory = historyDesensitization[table.tableName][columnKey] // 历史配置信息
      }
      columnMap[columnKey] = {
        dataLevelId: 1,
        dataMaskingType: 'md5',
        importColumn: true,
        masking: false,
        ...columnHistory,
      }
    })
    tableDesensitizationMap[table.tableName] = columnMap
  })
  return tableDesensitizationMap
}

/**
 * 数据库
 * @param tables
 * @param historyDesensitization
 */
export function initDesensitizationListForDatabase(
  tables: any[],
  historyDesensitization: any
) {
  console.log(tables, historyDesensitization)
}
